package com.wn.consumer06;

import com.rabbitmq.client.Channel;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author yellow Docter
 * @date 2023 -02-28
 * @desc
 */
@Component
@Slf4j
public class Consumer {

    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(
                            name="normal-queue",
                            arguments = {       //队列的属性
                                    @Argument(name = "x-dead-letter-exchange",value = "exchange-dlx"), //死信交换机
                                    @Argument(name = "x-dead-letter-routing-key",value = "lisi"),
                                    @Argument(name = "x-message-ttl",value = "10000",type = "java.lang.Long"),  // 消息是生命周期
                                    @Argument(name = "x-max-length",value = "3",type = "java.lang.Long"),      //消息的长度
                            }
                    ),
                    exchange = @Exchange(
                            name = "exchange-normal",
                            type = ExchangeTypes.DIRECT
                    ),
                    key = "zs"
            )
    )
    public void handlerMsg(String msg, Channel channel, Message message) throws IOException {
        //拒绝消息
        log.info("消息拒绝...");
        channel.basicReject(message.getMessageProperties().getDeliveryTag(),false);

    }

}
